﻿using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using DevExpress.XtraReports.UI;
using DevExpress.XtraPivotGrid;
using System.Collections.Generic;
using DXApplicationTangche.UC.成品出库单.service;
using System.Data;
using DXApplicationTangche.Utils;
using DevExpress.XtraGrid.Demos.util;
using DXApplicationTangche.UC.订单一览新.订单预览新.service;
using DXApplicationTangche.UC.订单一览新.辅料.service;
using DXApplicationTangche.UC.款式尺寸;
using mendian;
using DXApplicationTangche.DTO;
using DXApplicationTangche.UC.货号管理.service;
using DXApplicationTangche.UC.项目流程.Service;
using DXApplicationTangche.UC.订单一览新.销售确认单;
using DXApplicationTangche.UC.面料审核.Service;
using DXApplicationTangche.UC.客户CRM.Service;

namespace DXApplicationTangche.report
{
    public partial class XtraReport生产计划单带地址 : DevExpress.XtraReports.UI.XtraReport
    {
        private MaterialRequirementQueryDTO materialRequirementQueryDTO = new MaterialRequirementQueryDTO();
        private List<MaterialRequirementDTO> materialRequirementDTOs = new List<MaterialRequirementDTO>();
        private List<WIPBatchWIthMBomDTO> relevantWipBatchWIthMBomDTOList = new List<WIPBatchWIthMBomDTO>();
        private List<MaterialPurchaseTitleDTO> materialPurchaseTitleDTOS = new List<MaterialPurchaseTitleDTO>();
        private UC.客户CRM.Service.CustomerOrderCommitDTO addressDTO = new UC.客户CRM.Service.CustomerOrderCommitDTO();
        private ShopRightQueryFacadeDTO shopRightQueryFacadeDTO = new ShopRightQueryFacadeDTO();

        public XtraReport生产计划单带地址(MaterialRequirementQueryDTO materialRequirementQueryDTO)
        {
            InitializeComponent();
            this.materialRequirementQueryDTO = materialRequirementQueryDTO;
            this.materialRequirementDTOs = materialRequirementQueryDTO.materialRequirementDTOS;
            //this.relevantWipBatchWIthMBomDTOList = materialRequirementQueryDTO.relevantWipBatchWIthMBomDTOList;
            this.materialPurchaseTitleDTOS = materialRequirementQueryDTO.materialPurchaseTitleDTOS;
            this.shopRightQueryFacadeDTO = materialRequirementQueryDTO.shopRightQueryFacadeDTO;
            this.addressDTO = CRM客户Service.getOutSourcingByShopCd(materialRequirementQueryDTO.shopRightQueryFacadeDTO.shopCd);
            //this.addressDTO = CRM客户Service.getOutSourcingByShopCd("KASHIYAMA_SH");
            //订单信息尺寸清洗
            foreach (WIPBatchWIthMBomDTO wIPBatchWIthMBomDTO in materialRequirementQueryDTO.relevantWipBatchWIthMBomDTOList)
            {
                try { wIPBatchWIthMBomDTO.styleSizeCd = wIPBatchWIthMBomDTO.styleSizeCd.Replace("IGS_GROUP_SIZE-", "").Replace("EGS_GROUP_SIZE-", ""); } catch { }
                this.relevantWipBatchWIthMBomDTOList.Add(wIPBatchWIthMBomDTO);
            }
            //抬头绑定
            this.BindData();
            //面料库存和固定损耗
            this.DetailReport.DataSource = this.materialRequirementDTOs;
            this.BindTableData(this.materialRequirementDTOs);
            //订单信息
            this.DetailReport2.DataSource = this.relevantWipBatchWIthMBomDTOList;
            this.BindTableData订单();
            //采购订单信息
            this.DetailReport1.DataSource = this.materialPurchaseTitleDTOS;
            this.BindTableData采购订单();
            this.BindTableData采购明细();
        }
        
        /// <summary>
        /// 绑定表头
        /// </summary>
        private void BindData()
        {
            this.xrTableCell物料需求计划编码.Text = this.materialRequirementQueryDTO.materialPlanNo;
            this.xrTableCell面料出库审核人.Text = this.materialRequirementQueryDTO.mnemonic;
            this.xrTableCell金蝶出库单编码.Text = this.materialRequirementQueryDTO.fName;
            this.xrTableCell完成时间.Text = materialRequirementQueryDTO.completeDate.ToString();
            this.xrTableCell开始时间.Text = this.materialRequirementQueryDTO.createDate.ToString();
            this.xrTableCell实际出库审核人.Text = this.materialRequirementQueryDTO.stockOutMnemonic;
            this.xrTableCell最终成果物URL.Text = this.materialRequirementQueryDTO.achievementUrl;
            this.xrTableCell收货人信息.Text = this.addressDTO.customerName + " " + this.addressDTO.mobile;
            this.xrTableCell收货地址.Text = this.addressDTO.addressProvince + this.addressDTO.addressCity + this.addressDTO.addressDistrict + this.addressDTO.addressDetail;
            this.xrTableCell销售组织名称.Text = this.shopRightQueryFacadeDTO.orgName;
            this.xrLabel1.Text = this.shopRightQueryFacadeDTO.orgName + "生产计划单";
            this.xrLabel委托方.Text = "委托方 " + this.shopRightQueryFacadeDTO.shopName;
            //this.xrLabel1.Text = "KASHIYAMA" + "生产计划单";
            //this.xrLabel委托方.Text = "委托方 " + "上海坚山";
        }

        private void BindTableData(List<MaterialRequirementDTO> materialRequirementDTOs)
        {
            this.xrTableCell面料编码.DataBindings.Add("Text", materialRequirementDTOs, "fname");
            this.xrTableCell产成品需求数量.DataBindings.Add("Text", materialRequirementDTOs, "batchCount");
            this.xrTableCell固定损耗.DataBindings.Add("Text", materialRequirementDTOs, "ffixscrapqty");
            this.xrTableCell库存数量.DataBindings.Add("Text", materialRequirementDTOs, "inventory");
            this.xrTableCell未出库订单数量.DataBindings.Add("Text", materialRequirementDTOs, "todoBillCount");
            this.xrTableCell实际出库数.DataBindings.Add("Text", materialRequirementDTOs, "fabricScrapQty");
        }
        private void BindTableData订单()
        {
            this.xrTableCell订单号.DataBindings.Add("Text", DataSource, "orderNo");
            this.xrTableCell生产批号.DataBindings.Add("Text", DataSource, "batchNo");
            this.xrTableCell下单时间.DataBindings.Add("Text", DataSource, "orderDate");
            this.xrTableCell面料号.DataBindings.Add("Text", DataSource, "materialCode");
            this.xrTableCell款式名称.DataBindings.Add("Text", DataSource, "styleNameCn");
            this.xrTableCell尺码.DataBindings.Add("Text", DataSource, "styleSizeCd");
            this.xrTableCell数量.DataBindings.Add("Text", DataSource, "batchQuantity");
            this.xrTableCell订单固定损耗.DataBindings.Add("Text", DataSource, "ffixscrapqty");
            this.xrTableCell订单固定损耗总计.DataBindings.Add("Text", DataSource, "ffixscrapqtyAll");
            this.xrBarCode生产批次.DataBindings.Add("Text", DataSource, "batchNo");

            this.xrTableCell订单号2.DataBindings.Add("Text", DataSource, "orderNo");
            this.xrTableCell下单时间2.DataBindings.Add("Text", DataSource, "orderDate");
            this.xrTableCell面料号2.DataBindings.Add("Text", DataSource, "materialCode");
            this.xrTableCell款式名称2.DataBindings.Add("Text", DataSource, "styleNameCn");
            this.xrTableCell尺码2.DataBindings.Add("Text", DataSource, "styleSizeCd");
            this.xrTableCell数量2.DataBindings.Add("Text", DataSource, "batchQuantity");
            this.xrTableCell固定损耗2.DataBindings.Add("Text", DataSource, "ffixscrapqty");
            this.xrTableCell固定损耗总计2.DataBindings.Add("Text", DataSource, "ffixscrapqtyAll");
            this.xrTableCell受托加工制造番号.DataBindings.Add("Text", DataSource, "productNo");
            this.xrTableCell受托加工制造母番号.DataBindings.Add("Text", DataSource, "oyaProductNo");
            this.xrTableCell客户姓名.DataBindings.Add("Text", DataSource, "customerName");
        }
        private void BindTableData采购订单()
        {
            this.xrTableCell采购订单号.DataBindings.Add("Text", DataSource, "fnumber");
            this.xrTableCell采购时间.DataBindings.Add("Text", DataSource, "createDate");
            this.xrTableCell供应商.DataBindings.Add("Text", DataSource, "supplierName");
        }
        private void BindTableData采购明细()
        {
            //this.xrTableCell采购面料号.DataBindings.Add("Text", DataSource, "fname");
            //this.xrTableCell采购数量.DataBindings.Add("Text", DataSource, "fqty");

        }
    }

}
